<?php

namespace common\validate;


class StepCategory extends BaseValidate
{
    // 验证规则
    protected $rule = [];

    // Fields 验证场景定义
    public function sceneFields()
    {
        return $this;
    }

    // Find 验证场景定义
    public function sceneFind()
    {
        return $this->append('param', 'require')
            ->append('param.filter', 'array');
    }

    // Select 验证场景定义
    public function sceneSelect()
    {
        return $this->append('param', 'require')
            ->append('param.filter', 'array')
            ->append('param.page', 'array');
    }

    // Create 验证场景定义
    public function sceneCreate()
    {
        return $this->append('data.name', 'require|max:128')
            ->append('data.code', 'max:128')
            ->append('data.entity_id', 'integer|checkEntityId')
            ->append('data.is_standard', 'in:yes,no')
            ->append('data.task_type', 'in:free,inventory,episodes');
    }

    // Update 验证场景定义
    public function sceneUpdate()
    {
        return $this->append('data.id', 'require')
            ->append('data.name', 'max:128')
            ->append('data.code', 'max:128')
            ->append('data.parent_id', 'integer')
            ->append('data.entity_id', 'integer|checkEntityId')
            ->append('data.is_standard', 'in:yes,no')
            ->append('data.task_type', 'in:free,inventory,episodes');
    }

    // Delete 验证场景定义
    public function sceneDelete()
    {
        return $this->append('param.filter', 'require');
    }

    // BindEntityModule 验证场景定义
    public function sceneBindEntityModule()
    {
        return $this->append('data.id', 'require')
            ->append('data.entity_id', 'require|integer');
    }

    /**
     * 验证entity_id参数
     * @param $value
     * @param $compare
     * @param $data
     * @param $key
     * @param $key2
     * @return bool|string
     */
    public function checkEntityId($value, $compare, $data, $key, $key2)
    {
        if (isset($data['data']['parent_id']) && $data['data']['parent_id'] > 0 && $value > 0) {
            //如果父级id大于0 那么实体id就不能大于零
            return "can`t set entity_id = {$value} when parent_id greater than 0";
        }
        return true;
    }


    // GetStepCategoryPlan 验证场景定义
    public function sceneGetStepCategoryPlan()
    {
        return $this->append('filter.project_id', 'require|integer');
    }


    // SetStepCategoryIndex 验证场景定义
    public function sceneSetStepCategoryIndex()
    {
        return $this->append('data', 'require|array');
    }

    // GetPlayListStepCategoryData 验证场景定义
    public function sceneGetPlayListStepCategoryData()
    {
        return $this->append('param.filter.module_code', 'require')
            ->append('param.filter.project_id', 'require|integer')
            ->append('param.filter.episode_id', 'integer');
    }

    // MergeModuleStepCategoryList 验证场景定义
    public function sceneMergeModuleStepCategoryList()
    {
        return $this;
    }

    // sceneShowProjectSecondLevelList 验证场景定义
    public function sceneShowProjectSecondLevelList()
    {
        return $this->append('param.filter.project_id', 'require|integer');
    }

    // UpstreamRelation 验证场景定义
    public function sceneUpstreamRelation()
    {
        return $this->append('param.filter', 'array');
    }

    // GetStepCategoryListByEntity 验证场景定义
    public function sceneGetStepCategoryListByEntity()
    {
        return $this->append('param.entity_module_code', 'require|in:episode,shot,asset');
    }
}
